<script type="text/javascript">
$(function(){
	var pg = App.base.projList.ui, pp = pg.params || {},
		gd = pg.seek('grid');

	gd.mac('grid', {
		key: 'id',
		cols: [{
			field: 'name', title : '系统名称 ', width: 200,
			render: function(r, tr){
				return $('<span class="a"></span>').click(function(){
					App.open({
						title: '子系统信息',
						ctx: 'base',
						action: 'projEdit',
						model: true,
						params: r
					},function(){
						pg.callback(pp.id);
						gd.load()
					});
				}).append(r.name);
			}
		},{
			field: 'code', title : '英文编码', width: 200
		},{
			field: 'memo', title : '备忘录 ', width: 220
		},{
			field: 'status', title : '状态', width: 80,
			render: function(r) {
				return Cache.base.server.status[r.status];
			}
		},{
			field: 'id', title : '操作', width: 120,
			render: function(r) {
				var p = $('<div></div>');
				if (r.status == 0) {
					$('<span class="a center" style="width:100%"></span>').click(function(){
						if(App.logon.power('proj.stop')){
							$.post(App.ctx + '/dir/start.do', {
								ids: r.id,
								status: 1 
							}, function(rs){
								pg.callback(pp.id);
								gd.load();
							});
						}
					}).append('启用').appendTo(p);
				} else if (r.status == 1) {
					$('<span class="a center" style="width:100%"></span>').click(function(){
						if(App.logon.power('proj.stop')){
							$.post(App.ctx + '/dir/stop.do', {
								ids: r.id,
								status: 0 
							}, function(rs){
								pg.callback(pp.id);
								gd.load();
							});
						}
					}).append('停用').appendTo(p);
				}
				return p;
			}
		}],
		loader: {
			url: App.ctx + '/proj/list.do',
			params: {
				pageNo: 1, pageSize: 10,
				parentId: pp.id
			},
			autoLoad: true
		},
		pagerLength: 10
	});

	if (App.logon.power('proj.save')){
		pg.seek('add').click(function(){
			App.open({
				title: '系统信息',
				ctx:'base',
				action: 'projEdit',
				model: true,
				params: {
					parentId: pp.id
				}
			},function(){
				pg.callback(pp.id);
				gd.load();
			});
		}).show();
	}
	pg.seek('key').keydown(function(e) {
		if (e.keyCode == 13)
			gd.load({ key: $(this).val() });
	});
	pg.seek('find').click(function(e) {
		gd.load({
			key: pg.seek('key').val()
		});
	});
	
	function adjust(){
		var h = pg.parent().parent().height();
		pg.height(h);
		gd.parent().height(h-50);
		gd.adjust();
	}
	$(window).resize(adjust);
	adjust();
});
</script>
<div class="head">
	<button name="add" class="fl hidden">添加子系统</button>
	<span>&nbsp;&nbsp;&nbsp;&nbsp; 关键字：</span>
	<input type="text" name="key" />
	<button name="find">查找</button>
</div>
<div class="body">
	<div class="grid" name="grid"></div>
</div>